package com.ld.admin.util.daliySentence.impl;

import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.ld.admin.util.daliySentence.DaliySentence;
import com.ld.admin.util.daliySentence.DaliySentenceUtil;
import com.ld.admin.util.daliySentence.model.DaliySentenceModel;
import com.ld.shieldsb.common.core.util.JsoupUtil;

/**
 * 
 * 欧路词典
 * 
 * @author <a href="mailto:donggongai@126.com" target="_blank">吕凯</a>
 * @date 2020年1月8日 上午11:00:38
 *
 */
public class DaliySentenceEudic implements DaliySentence {
    public static final String KEY = "eudic";
    public static final String NAME = "欧路词典";
    public static final String URL = "http://dict.eudic.net/home/dailysentence";
    public static final String LINK_URL = "http://dict.eudic.net/home/dailysentence";
    public static final String DESCRIPTION = ""; // 描述

    @Override
    public DaliySentenceModel getSentence() {

        String htmlContent = "";
        DaliySentenceModel model = null;

        Document document = JsoupUtil.getRemoteURLDocument(getURL(), null);
        if (document != null) {
            model = new DaliySentenceModel();
            Elements containerEle = document.select("div.containter");
            if (containerEle != null) {
                Elements image = containerEle.select("#showerimg"); // 图片
                if (image != null) {
                    String picUrl = image.attr("src");
                    htmlContent = "<img src=\"" + picUrl + "\" width='270' >" + "<br/>"; // height='180'
                    model.setPicUrl(picUrl); // 图片
                }

                String content = containerEle.select(".sect_en").text() + "<br/>";
                content += containerEle.select(".sect-trans").text() + "";

                htmlContent += content;
                htmlContent += DaliySentenceUtil.getLinkedStr(getLinkURL(), getName());

                model.setHtmlContent(htmlContent);
                model.setContent(content);
//                model.setOrigin(origin);
                model.setBaseInfo(getBaseInfo());
            }
        }
        return model;
    }

    @Override
    public String getKey() {
        return KEY;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getURL() {
        return URL;
    }

    @Override
    public String getLinkURL() {
        return LINK_URL;
    }

    @Override
    public String getDescription() {
        return DESCRIPTION;
    }

}
